//
//  HSTargetAction.m
//  ObjcDemo
//
//  Created by fan on 2021/10/15.
//

#import "HSTargetAction.h"

@interface HSTargetAction ()

@property (nonatomic, copy) NSString *targetClass;

@property (nonatomic, copy) NSString *actionMethod;

@property (nonatomic, strong) HSParameters *parameters;

@property (nonatomic, copy) NSString *swiftName;

@end

@implementation HSTargetAction

+ (HSTargetAction *)targetClass:(NSString *)targetClass {
    return [self targetClass:targetClass actionMethod:nil parameters:nil];
}

+ (HSTargetAction *)targetClass:(NSString *)targetClass actionMethod:(NSString *)actionMethod {
    return [self targetClass:targetClass actionMethod:actionMethod parameters:nil];
}

+ (HSTargetAction *)targetClass:(NSString *)targetClass actionMethod:(NSString *)actionMethod parameters:(HSParameters *)parameters{
    HSTargetAction *tarAct = [[HSTargetAction alloc] init];
    tarAct.targetClass = targetClass;
    tarAct.actionMethod = actionMethod;
    tarAct.parameters = parameters;
    return tarAct;
}

+ (HSTargetAction *(^)(NSString *))cls {
    return ^HSTargetAction *(NSString *cls) {
        HSTargetAction *act = [[HSTargetAction alloc] init];
        act.targetClass = cls;
        return act;
    };
}

- (HSTargetAction *(^)(NSString *))mtd {
    return ^HSTargetAction *(NSString *mtd) {
        self.actionMethod = mtd;
        return self;
    };
}

- (HSTargetAction *(^)(HSParameters *))params{
    return ^HSTargetAction *(HSParameters *params) {
        self.parameters = params;
        return self;
    };
}
// 能在编译期检查类和方法的方法
+ (HSTargetAction *(^)(Class))clas{
    return ^HSTargetAction *(Class clas) {
        HSTargetAction *act = [[HSTargetAction alloc] init];
        act.targetClass = NSStringFromClass(clas);
        return act;
    };
}
- (HSTargetAction *(^)(SEL))mted {
    return ^HSTargetAction *(SEL mtd) {
        self.actionMethod = NSStringFromSelector(mtd);
        return self;
    };
}

- (HSTargetAction *(^)(NSString *))swiftModuleName{
    return ^HSTargetAction *(NSString *swiftModuleName) {
        self.swiftName = swiftModuleName;
        return self;
    };
}

- (NSString *)targetClass {
    if (self.swiftName && self.swiftName.length > 0 && ![_targetClass containsString:self.swiftName]) {
        return [NSString stringWithFormat:@"%@.%@",self.swiftName, _targetClass];
    }else{
        return _targetClass;
    }
}

@end
